﻿
using DataService.Common;
using DataService.Core.Common;
using DataService.Core.ServiceDTO;
using System;
using System.Data;
using System.Data.Common;
using System.Text;

namespace DataService.DataAccessLayer
{
    public class SqlServerProvider : DatabaseProvider
    {
        public override DatabaseType DBType => DatabaseType.SqlServer;
        public override Type DatabaseProviderType => typeof(SqlServerProvider);
        //  public override IsolationLevel _IsolationLevel => IsolationLevel.ReadCommitted;
        private static DbProviderFactory _MSSQLFactory;
        /// <summary>工厂</summary>
        public override DbProviderFactory ProviderFactory
        {
            get
            {
                if (_MSSQLFactory == null)
                {
                    lock (typeof(SqlServerProvider))
                    {
                        string dir = FilePathHelper.BasePath + "System.Data.SqlClient.dll";
                        _MSSQLFactory = GetProviderFactory(dir, "System.Data.SqlClient.SqlClientFactory");
                      //  System.Console.WriteLine("实例化MSSQL驱动工厂");
                    }
                    //下面需要安装一些组件，以后再优化这里
                    //lock (typeof(SqlServerProvider))
                    //{
                    //    // Microsoft 是最新的跨平台版本，优先使用
                    //    //if (_Factory == null) _Factory = GetProviderFactory("Microsoft.Data.SqlClient.dll", "Microsoft.Data.SqlClient.SqlClientFactory");
                    //    if (_Factory == null) _Factory = GetProviderFactory(string.Empty, "Microsoft.Data.SqlClient.SqlClientFactory");
                    //    if (_Factory == null) _Factory = GetProviderFactory("System.Data.SqlClient.dll", "System.Data.SqlClient.SqlClientFactory");
                    //}
                }
                return _MSSQLFactory;
            }
        }


    }
}
